local M = {
  "numToStr/Comment.nvim",
  enabled = true,
  event = { "BufReadPre", "BufNewFile" },
  -- keys = {
  --   { 'mgc', mode = { 'n', 'v' }, 'gcc' },
  -- },
  dependencies = {
    -- 依赖 nvim-treesiter 插件才能使用，增强的注释插件
    "JoosepAlviste/nvim-ts-context-commentstring",
  },
}

function M.config()
  local comment = require "Comment"
  local ts_context_commentstring = require "ts_context_commentstring.integrations.comment_nvim"

  -- `gco` - Insert comment to the next line and enters INSERT mode
  -- `gcO` - Insert comment to the previous line and enters INSERT mode
  -- `gcA` - Insert comment to end of the current line and enters INSERT mode
  -- # Linewise
  --
  -- `gcw` - Toggle from the current cursor position to the next word
  -- `gc$` - Toggle from the current cursor position to the end of line
  -- `gc}` - Toggle until the next blank line
  -- `gc5j` - Toggle 5 lines after the current cursor position
  -- `gc8k` - Toggle 8 lines before the current cursor position
  -- `gcip` - Toggle inside of paragraph
  -- `gca}` - Toggle around curly brackets
  --
  -- # Blockwise
  --
  -- `gb2}` - Toggle until the 2 next blank line
  -- `gbaf` - Toggle comment around a function (w/ LSP/treesitter support)
  -- `gbac` - Toggle comment around a class (w/ LSP/treesitter support)
  comment.setup {
    pre_hook = ts_context_commentstring.create_pre_hook(),
    ---Function to call before (un)comment
    -- pre_hook = commentstring.create_pre_hook(),
    -- pre_hook = function(ctx)
    --   local loaded, ts_comment = pcall(require, "ts_context_commentstring.integrations.comment_nvim")
    --   if loaded and ts_comment then
    --     return ts_comment.create_pre_hook()(ctx)
    --   else
    --     vim.notify "Not found 'nvim-ts-context-commentstring' plugin"
    --   end
    -- end,
  }
end

return M
